﻿#include "DoubleCircleLinedListWithHead.h"

// 头部操作测试
void test1()
{
	ListNode* phead = NULL;
	DoubleLinkedListInit(&phead);

	DoubleLinkedListPushFront(phead, 5);
	DoubleLinkedListPushFront(phead, 4);
	DoubleLinkedListPushFront(phead, 3);
	DoubleLinkedListPushFront(phead, 2);
	DoubleLinkedListPushFront(phead, 1);

	DoubleLinkedListTraverse(phead);
	DoubleLinkedListRetraverse(phead);

	DoubleLinkedListPopFront(phead);
	DoubleLinkedListPopFront(phead);
	DoubleLinkedListPopFront(phead);
	DoubleLinkedListTraverse(phead);

	DoubleLinkedListPopFront(phead);
	DoubleLinkedListPopFront(phead);
	DoubleLinkedListTraverse(phead);

	// DoubleLinkedListPopFront(phead);
}

// 尾部操作测试
void test2()
{
	ListNode* phead = NULL;
	DoubleLinkedListInit(&phead);
	DoubleLinkedListPushBack(phead, 1);
	DoubleLinkedListPushBack(phead, 2);
	DoubleLinkedListPushBack(phead, 3);
	DoubleLinkedListPushBack(phead, 4);
	DoubleLinkedListPushBack(phead, 5);

	DoubleLinkedListTraverse(phead);
	DoubleLinkedListRetraverse(phead);

	DoubleLinkedListPopBack(phead);
	DoubleLinkedListPopBack(phead);
	DoubleLinkedListTraverse(phead);

	DoubleLinkedListPopBack(phead);
	DoubleLinkedListPopBack(phead);
	DoubleLinkedListPopBack(phead);
	DoubleLinkedListTraverse(phead);

	// DoubleLinkedListPopBack(phead);
}

// 中部/查找操作测试
void test3()
{
	ListNode* phead = NULL;
	DoubleLinkedListInit(&phead);
	DoubleLinkedListPushBack(phead, 1);
	DoubleLinkedListPushBack(phead, 2);
	DoubleLinkedListPushBack(phead, 3);
	DoubleLinkedListPushBack(phead, 4);
	DoubleLinkedListPushBack(phead, 5);

	DoubleLinkedListInsert(phead, 2, 666);
	DoubleLinkedListInsert(phead, 5, 999);
	DoubleLinkedListInsert(phead, 0, 111);

	DoubleLinkedListTraverse(phead);

	DoubleLinkedListErase(phead, 0);
	DoubleLinkedListTraverse(phead);

	DoubleLinkedListErase(phead, 2);
	DoubleLinkedListTraverse(phead);

	DoubleLinkedListErase(phead, 4);
	DoubleLinkedListTraverse(phead);

	ListNode* node = DoubleLinkedListFind(phead, 999);
	if (node == NULL)
	{
		printf("no found\n");
	}

	ListNode* node2 = DoubleLinkedListFind(phead, 5);
	if (node2 != NULL)
	{
		printf("%d\n", node2->data);
	}
}

int main() 
{
	test3();
	return 0;
}